const cmd = require("node-cmd")
import path from "path"

export class UseComponent {
    // constructor(foo: string, componentName: string, projectRoot: string) {
    //     const command = `cd ${path.join(projectRoot, "second")} && node main.js -type ${foo} -root ${projectRoot} -componentName ${componentName}`
    //     cmd.run(command)
    //     console.log(command);
    // }

    private root: string

    constructor(projectRoot: string) {
        this.root = path.join(projectRoot, "second")
    }

    public run(foo: string, obj: object) {
        const keys = Object.keys(obj)
        let parameter = ' '
        for (let i = 0; i < keys.length; i++) {
            parameter += `-${keys[i]} ${obj[keys[i] as keyof object]} `
        }
        const command = `cd ${this.root} && node main.js -func ${foo}` + parameter
        cmd.run(command)
        console.log(command);
    }
}